A Rust implementation of the xxHash algorithm.
Examples
These examples use XxHash64
but the same ideas can be
used for XxHash32
or XxHash3_64
.
Hashing arbitrary data
When all the data is available at once
use XxHash64;
let seed = 1234;
let hash = oneshot;
assert_eq!;
When the data is streaming
use Hasher as _;
use XxHash64;
let seed = 1234;
let mut hasher = with_seed;
hasher.write;
hasher.write;
hasher.write;
let hash = hasher.finish;
assert_eq!;
In a HashMap
With a default seed
use ;
use XxHash64;
let mut hash = default;
hash.insert;
assert_eq!;
With a random seed
use HashMap;
use xxhash64;
let mut hash = default;
hash.insert;
assert_eq!;
With a fixed seed
use HashMap;
use xxhash64;
let mut hash = with_hasher;
hash.insert;
assert_eq!;
Feature Flags
name | description |
---|---|
xxhash32 | Include the XxHash32 algorithm |
xxhash64 | Include the XxHash64 algorithm |
xxhash3_64 | Include the XxHash3_64 algorithm |
random | Create random instances of the hashers |
serialize | Serialize and deserialize hasher state with Serde |
std | Use the Rust standard library. Enable this if you want SIMD support in XxHash3_64 |
alloc | Use the Rust allocator library. Enable this if you want to create XxHash3_64 with dynamic secrets |
Benchmarks
See benchmarks in the comparison README.
Contributing
- Fork it (https://github.com/shepmaster/twox-hash/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Add a failing test.
- Add code to pass the test.
- Commit your changes (
git commit -am 'Add some feature'
) - Ensure tests pass.
- Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request